<?php

namespace App\Home\Controllers;

use App\Home\Filters\WorshipPptFilter;
use App\Home\Models\WorshipPpt;
use App\Home\Requests\WorshipPptRequest;
use App\Home\Resources\WorshipPptResource;
use Illuminate\Http\Request;

class WorshipPptController extends Controller
{
    public function store(
        WorshipPptRequest $request, 
        WorshipPpt $worshipPpt
    ){
        $inputs = $request->validated();
        $worshipPpt = $worshipPpt->add($inputs);

        return $this->created(WorshipPptResource::make($worshipPpt));
    }

    public function update(
        WorshipPptRequest $request, 
        WorshipPpt $worshipPpt
    ){
        $inputs = $request->validated();
        $worshipPpt->update($inputs);

        return $this->created(WorshipPptResource::make($worshipPpt));
    }

    public function destroy(
        WorshipPpt $worshipPpt
    ){
        $worshipPpt->delete();
        return $this->noContent();
    }

    public function index(
        WorshipPptRequest $request,
        WorshipPptFilter $filter
    ){
        $fields = [
            "*",
        ];
        $worshipPpts = WorshipPpt::query()
            ->filter($filter)
            ->select($fields)
            ->paginate();

        return $this->ok(WorshipPptResource::collection($worshipPpts));
    }

    public function show(
        Int $id
    ){
        $fields = [
            "*",
        ];
        $worshipPpt = WorshipPpt::query()
            ->select($fields)
            ->find($id);
        return $this->ok(WorshipPptResource::make($worshipPpt));
    }
}
